Skip to content

Conversation

@aheejin
Copy link
Member

@aheejin aheejin commented May 25, 2022

#17003 added "terminating" to exception messages, but some people might
want to use the message in non-terminating cases. This changes
emscripten_format_exception to __get_exception_message, and
separately adds __get_terminating_exception_message. Adds two
underscores not to clash with the global namespace.

__get_exception_message prints messages like

exception of type char
exception of type std::runtime_error: abc
exception of type myexception: My exception happened

__get_terminating_exception_message prints messages like

terminating with uncaught exception of type char
terminating with uncaught exception of type std::runtime_error: abc
terminating with uncaught exception of type myexception: My exception happened

 emscripten-core#17003 added "terminating" to exception messages, but some people might
want to use the message in non-terminating cases. This changes
`emscripten_format_exception` to `__get_exception_message`, and
separately adds `__get_terminating_exception_message`. Adds two
underscores not to clash with the global namespace.

`__get_exception_message` prints messages like
```
uncaught exception of type char
uncaught exception of type std::runtime_error: abc
uncaught exception of type myexception: My exception happened
```
`__get_terminating_exception_message` prints messages like
```
terminating with uncaught exception of type char
terminating with uncaught exception of type std::runtime_error: abc
terminating with uncaught exception of type myexception: My exception happened
```
@aheejin aheejin requested a review from sbc100 May 25, 2022 17:38
@aheejin
Copy link
Member Author

aheejin commented May 25, 2022

cc @hoodmane

@hoodmane
Copy link
Collaborator

I am also not sure that the adjective "uncaught" should be in there. We caught it from JavaScript instead of inside of wasm, but depending on your perspective the error may or may not be "uncaught".

// the exception, if necessary. By incrementing and decrementing the refcount
// we trigger the free'ing of the exception if its refcount was zero.
___cxa_increment_exception_refcount(p);
console.log(Module["formatException"](p).replace(/0x[0-9a-f]*/, "xxx"));
Copy link
Member Author

@aheejin aheejin May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoodmane By the way I have a question. Is there a reason we can't call this just like

console.log(formatException(p));

?

The same for Module["_throw_exc"] in line 1648.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, try it and see?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From outside the module you would need Module["formatException"].. but for JS that is inside the module (e.g. EM_ASM and EM_JS code) then you can just do formatException.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Changed them to direct calls.

@aheejin
Copy link
Member Author

aheejin commented May 25, 2022

I am also not sure that the adjective "uncaught" should be in there. We caught it from JavaScript instead of inside of wasm, but depending on your perspective the error may or may not be "uncaught".

I think that makes sense. Removed it.

return result;
}

char* __get_exception_terminate_message(void *thrown_object) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't have any current caller of this yet, but we will do soon (perhaps in debug builds, or some opt-in configuration)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'd like to use it later, and this PR doesn't have a direct test for this, but I think holding this small piece off is probably not worth it..

@aheejin aheejin merged commit 1f6b136 into emscripten-core:main May 25, 2022
@aheejin aheejin deleted the exception_msg branch May 25, 2022 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants